package com.tencent.wxpay.demo.util;

import com.tencent.wxpay.WXPay;
import com.tencent.wxpay.demo.service.impl.OrderQueryServiceImpl;

import java.io.InputStream;
import java.util.Properties;

/**
 * 测试初始化调用
 */
public class TestUtil {
    public static boolean init(){
        // 读取配置文件
        Properties properties = new Properties();
        InputStream inputStream = OrderQueryServiceImpl.class.getClassLoader().getResourceAsStream("wxpay.properties");
        try {
            properties.load(inputStream);
            WXPay.initSDKConfiguration(properties.getProperty("KEY"),
                    properties.getProperty("APPID"),
                    properties.getProperty("MCHID"),
                    properties.getProperty("SUBMCHID"),
                    properties.getProperty("CERT_LOCAL_PATH"),
                    properties.getProperty("CERT_PASSWORD")
            );
            System.out.println("初始化成功");
            return true;
        } catch (Exception e) {
            System.out.println("初始化失败");
            e.printStackTrace();
        }
        return false;
    }
}
